import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { PublicConfigDto } from './dto/config.dto';
import { PublicConfig } from './entities/config.entity';

@Injectable()
export class PublicConfigService {
  // 使用InjectRepository装饰器并引入Repository这样就可以使用typeorm的操作了
  constructor(
    @InjectRepository(PublicConfig)
    private readonly publicConfigRepository: Repository<PublicConfig>,
  ) {}
  
  // 获取公共配置
  async config(): Promise<PublicConfigDto> {
    // let publicConfig: PublicConfigDto[] = await this.publicConfigRepository.query(`SELECT * FROM public_config`) //(`SELECT Count(*) as count FROM public_config`);
    let publicConfig: PublicConfigDto = await this.publicConfigRepository.findOneBy({id: 1})
    return publicConfig;
  }

}
